﻿/*create proc MergeBookOfWork
as

merge into BookOfWork2013 as Target
using BookOfWorkTemp as Source
	on Target.PeriodYear = Source.PeriodYear
	and Target.InitiativeId = Source.InitiativeId
	and Target.AccountLevelId = Source.AccountLevelId
	and Target.ProgramId = Source.ProgramId
	and Target.ProjectId = Source.ProjectId
	and Target.BillingClientGocCode = Source.BillingClientGocCode
	and Target.ClientGocCode = Source.ClientGocCode
	and Target.SystemGOCCode = Source.SystemGOCCode
	and Target.ProgramType = Source.ProgramType
	and Target.ProjectType = Source.ProjectType
	and Target.January = Source.January
	and Target.February = Source.February
	and Target.March = Source.March
	and Target.April = Source.April
	and Target.May = Source.May
	and Target.June = Source.June
	and Target.July = Source.July
	and Target.August = Source.August
	and Target.September = Source.September
	and Target.October = Source.October
	and Target.November = Source.November
	and Target.December = Source.December
	and Target.YearToDate = Source.YearToDate
	and Target.FullYear = Source.FullYear
when matched then 
	update set Target.LastUpdate = GetDate()
when not matched then
	insert values 
	(
		Source.PeriodYear,
		Source.AccountLevelId,
		Source.AccountLevel1,
		Source.AccountLevel2,
		Source.AccountLevel3,
		Source.InitiativeId,
		Source.InitiativeName,
		Source.ProgramId,
		Source.ProgramName,
		Source.ProjectId,
		Source.ProjectName,
		Source.ProgramManager,
		Source.ProgramSTLT,
		Source.ProgramSMT,
		Source.ProgramStartDate,
		Source.ProgramEndDate,
		Source.STLT,
		Source.SMT,
		Source.ProjectStatus,
		Source.ProjectStartDate,
		Source.ProjectEndDate,
		Source.ProjectManager,
		Source.BillingClientGocCode,
		Source.Client3Code,
		Source.Client3Name,
		Source.Client4Code,
		Source.Client4Name,
		Source.Client5Code,
		Source.Client5Name,
		Source.Client6Code,
		Source.Client6Name,
		Source.Client7Code,
		Source.Client7Name,
		Source.Client8Code,
		Source.Client8Name,
		Source.Client9Code,
		Source.Client9Name,
		Source.Client10Code,
		Source.Client10Name,
		Source.ClientGocCode,
		Source.ClientSsbCitiIndicator,
		Source.ClientRegion,
		Source.MSJV,
		Source.System5Code,
		Source.System5Name,
		Source.System6Code,
		Source.System6Name,
		Source.System7Code,
		Source.System7Name,
		Source.System8Code,
		Source.System8Name,
		Source.System9Code,
		Source.System9Name,
		Source.System10Code,
		Source.System10Name,
		Source.SystemGOCCode,
		Source.SystemSSBCitiIndicator,
		Source.SystemRegion,
		Source.SystemRegionConsolidated,
		Source.LOB,
		Source.RuntheBankBuildtheBank,
		Source.ProgramProjectLinkIndicator,
		Source.WorkTypeFinancials,
		Source.InitiativeInvestimentCategory,
		Source.ProgramInvestimentCategory,
		Source.ProgramCapitalizedIndicator,
		Source.ProgramStatus,
		Source.ProgramType,
		Source.ProjectCapitalization,
		Source.BowFlag,
		Source.BowFlag2,
		Source.ProjectType,
		Source.Sector4,
		Source.REVBDGStartDate,
		Source.REVBDGEndDate,
		Source.ProgramCarryoverIndicator,
		Source.IsCompetitiveLandscape,
		Source.TaxonomyName,
		Source.CURate,
		Source.IsRelease,
		Source.FirstOfProgramDesc,
		Source.AdjustedFlag,
		Source.LobParent,
		Source.January,
		Source.JanuaryNonBow,
		Source.February,
		Source.FebruaryNonBow,
		Source.March,
		Source.MarchNonBow,
		Source.April,
		Source.AprilNonBow,
		Source.May,
		Source.MayNonBow,
		Source.June,
		Source.JuneNonBow,
		Source.July,
		Source.JulyNonBow,
		Source.August,
		Source.AugustNonBow,
		Source.September,
		Source.SeptemberNonBow,
		Source.October,
		Source.OctoberNonBow,
		Source.November,
		Source.NovemberNonBow,
		Source.December,
		Source.DecemberNonBow,
		Source.YearToDate,
		Source.FullYear,
		Source.YearToDateNonBow,
		Source.FullYearNonBow,
		Source.ReferenceDate,
		GetDate()
	);
	
Delete from BookOfWorkTemp*/